package com.feng.seata.tcc.action;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

@LocalTCC
public interface IStockTccAction {
    /**
     * 预扣库存
     *
     * @param businessActionContext
     * @param productId
     * @param buyNum
     * @return
     */
    @TwoPhaseBusinessAction(name = "prepareDeductStock", commitMethod = "commitDeductStock", rollbackMethod = "rollbackDeductStock", useTCCFence = true)
    boolean prepareDeductStock(BusinessActionContext businessActionContext,
                               @BusinessActionContextParameter(paramName = "productId") Long productId,
                               @BusinessActionContextParameter(paramName = "buyNum") Integer buyNum);

    /**
     * 提交被扣库存
     *
     * @param businessActionContext
     * @return
     */
    boolean commitDeductStock(BusinessActionContext businessActionContext);

    /**
     * 回滚被扣库存
     *
     * @param businessActionContext
     * @return
     */
    boolean rollbackDeductStock(BusinessActionContext businessActionContext);
}